<?php

/**
 * product actions.
 *
 * @package    HypnosisQueen
 * @subpackage product
 * @author     SoftXpert
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class shopCartAdminOrdersActions extends SXActions
{

    /**
     * list the user orders
     * @param sfWebRequest $request 
     */
    public function executeIndex(sfWebRequest $request)
    {
        $page        = $request->getParameter('page', 1);
        $query       = UserOrderTable::getInstance()->getAllUserOrders();
        $this->pager = $this->createPager('UserOrder', $query, $page, sfConfig::get('app_list_table_record_number'));
    }

    public function executeShowUserDetails(sfWebRequest $request)
    {
        // to return deleted prdoucts
        $orderId     = $request->getParameter('oid');
        $this->order = UserOrderTable::getInstance()->findOneById($orderId);
        $this->forward404Unless($this->order);
    }

    public function executeShowOrderDetails(sfWebRequest $request)
    {
        // to return deleted prdoucts
        Doctrine_Manager::getInstance()->getCurrentConnection()->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, FALSE);

        $orderId            = $request->getParameter('oid');
        $this->orderDetails = OrderDetailsTable::getInstance()->getOrderDetails($orderId)->execute();
        if (sizeof($this->orderDetails) == 0)
        {
            // that is mean the user try to send rong $orderId
            $this->forward404();
        }
    }

    public function executeUpdateOrderStatues(sfWebRequest $request)
    {
        $orderId = $request->getParameter('oid');
        $order   = UserOrderTable::getInstance()->findOneById($orderId);
        $this->forward404Unless($order);

        $form = new UserOrderStatuesForm($order);
        if ($request->isMethod(sfWebRequest::POST))
        {
            $form->bind($request->getParameter($form->getName()));
            if ($form->isValid())
            {
                $form->save();
                return $this->renderText('SUCESS');
            }
        }
        return $this->renderText('Faild');
    }

}
